package org.openfans.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.openfans.util.HtmlEncoder;

/**
 * Description：<br>
 * Date：2006-5-23<br>
 * 
 * @author pesome<br>
 * @email:pesome@gmail.com<br>
 */
public class Article extends PersistentObject {
	public static final int ORDER_BY_COMMENT_COUNT_DESC = 2;

	public static final int ORDER_BY_HOT_DESC = 1;

	public static final int ORDER_BY_SUBMIT_DATE_DESC = 0;

	public static final int ORDER_BY_TITLE_ASC = 4;

	public static final int ORDER_BY_USED_NUMBER_DESC = 3;

	public static String getOrder(int type) {
		switch (type) {
		case ORDER_BY_SUBMIT_DATE_DESC:
			return "article_id desc";
		case ORDER_BY_HOT_DESC:
			return "hot desc";
		case ORDER_BY_COMMENT_COUNT_DESC:
			return "comment_count desc";
		case ORDER_BY_TITLE_ASC:
			return "title asc";
		case ORDER_BY_USED_NUMBER_DESC:
			return "used_num desc";
		default:
			return "article_id desc";
		}
	}

	/**
	 * @uml.property name="articleId"
	 */
	private int articleId;

	private int commentCount;

	private Set<Comment> comments;

	/**
	 * @uml.property name="content"
	 */
	private String content;

	/**
	 * 写article的fans
	 * 
	 * @uml.property name="fans"
	 * @uml.associationEnd
	 */
	private Fans fans;

	private int hot;

	/**
	 * ��ƪ���µ�link�б?�û�����������Ӷ��
	 * 
	 * @uml.property name="linkList"
	 */
	private List<Link> linkList;

	/**
	 * 写article的时间
	 */
	private Date publishDate;

	/**
	 * 推荐article的fans
	 */
	private Fans recomFans;

	/**
	 * 推荐这个article的时间
	 */
	private Date submitDate;

	private Set<Tag> tagSet;

	/**
	 * @uml.property name="title"
	 */
	private String title;

	/**
	 * 文章的原文地址，如果是直接本站发表的就为空
	 */

	private String url;

	private String source;

	private String author;

	private Set<Fans> savedFansSet;

	private int savedNum;

	private int usedNum;

	private int uselessNum;

	public void addComment(Comment comment) {
		if (comments == null) {
			comments = new HashSet<Comment>();
		}
		comments.add(comment);
		commentCount++;
	}

	public void addHot(int i) {
		hot += i;
	}

	public void addLink(Link l) {
		if (linkList == null) {
			linkList = new ArrayList<Link>();
		}
		linkList.add(l);
	}

	public void addTag(Tag tag) {
		if (tagSet == null) {
			tagSet = new HashSet<Tag>();
		}
		tagSet.add(tag);
	}

	public void addTags(Set<Tag> tags) {
		if (tagSet == null) {
			tagSet = new HashSet<Tag>();
		}
		tagSet.addAll(tags);
	}

	public void addUsedNum(int i) {
		this.usedNum++;
	}

	public void addUselessNum(int i) {
		this.uselessNum++;
	}

	/**
	 * @return Returns the articleId.
	 * @uml.property name="articleId"
	 */
	public int getArticleId() {
		return articleId;
	}

	public int getCommentCount() {
		return commentCount;
	}

	public Set getComments() {
		return comments;
	}

	/**
	 * @return Returns the content.
	 * @uml.property name="content"
	 */
	public String getContent() {
		return content;
	}

	/**
	 * @return Returns the fans.
	 * @uml.property name="fans"
	 */
	public Fans getFans() {
		return fans;
	}

	public int getHot() {
		return hot;
	}

	public String getHtmlContent() {
		return HtmlEncoder.encode(content);
	}

	/**
	 * @return Returns the linkList.
	 * @uml.property name="linkList"
	 */
	public List<Link> getLinkList() {
		return linkList;
	}

	public Date getPublishDate() {
		return publishDate;
	}

	public Fans getRecomFans() {
		return recomFans;
	}

	public String getShortContent() {
		if (content.length() > 200) {
			return HtmlEncoder.encode(content.substring(0, 200) + "......");
		} else {
			return HtmlEncoder.encode(content);
		}
	}

	public Date getSubmitDate() {
		return submitDate;
	}

	public Set<Tag> getTagSet() {
		return tagSet;
	}

	/**
	 * @return Returns the title.
	 * @uml.property name="title"
	 */
	public String getTitle() {
		return title;
	}

	public String getUrl() {
		return url;
	}

	/**
	 * @return Returns the usedNum.
	 * @uml.property name="usedNum"
	 */
	public int getUsedNum() {
		return usedNum;
	}

	public int getUselessNum() {
		return uselessNum;
	}

	public void removeComment(Comment comment) {
		comments.remove(comment);
		commentCount--;
	}

	public void removeLink(Link l) {
		if (linkList != null) {
			linkList.remove(l);
		}
	}

	/**
	 * @param articleId
	 *            The articleId to set.
	 * @uml.property name="articleId"
	 */
	public void setArticleId(int articleId) {
		this.articleId = articleId;
	}

	public void setCommentCount(int commentCount) {
		this.commentCount = commentCount;
	}

	public void setComments(Set<Comment> comments) {
		this.comments = comments;
	}

	/**
	 * @param content
	 *            The content to set.
	 * @uml.property name="content"
	 */
	public void setContent(String content) {
		this.content = content;
	}

	/**
	 * @param fans
	 *            The fans to set.
	 * @uml.property name="fans"
	 */
	public void setFans(Fans fans) {
		this.fans = fans;
	}

	public void setHot(int hot) {
		this.hot = hot;
	}

	/**
	 * @param linkList
	 *            The linkList to set.
	 * @uml.property name="linkList"
	 */
	public void setLinkList(List<Link> linkList) {
		this.linkList = linkList;
	}

	public void setPublishDate(Date publishDate) {
		this.publishDate = publishDate;
	}

	public void setRecomFans(Fans recomFans) {
		this.recomFans = recomFans;
	}

	public void setSubmitDate(Date submitDate) {
		this.submitDate = submitDate;
	}

	public void setTagSet(Set<Tag> tagSet) {
		this.tagSet = tagSet;
	}

	/**
	 * @param title
	 *            The title to set.
	 * @uml.property name="title"
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	/**
	 * @param usedNum
	 *            The usedNum to set.
	 * @uml.property name="usedNum"
	 */
	public void setUsedNum(int usedNum) {
		this.usedNum = usedNum;
	}

	public void setUselessNum(int uselessNum) {
		this.uselessNum = uselessNum;
	}

	public Set<Fans> getSavedFansSet() {
		return savedFansSet;
	}

	public void setSavedFansSet(Set<Fans> savedFansSet) {
		this.savedFansSet = savedFansSet;
	}

	public void removeSavedFans(Fans fans) {
		savedFansSet.remove(fans);
		savedNum--;
	}

	public void addSavedFans(Fans fans) {
		if (savedFansSet == null) {
			savedFansSet = new HashSet<Fans>();
		}
		savedFansSet.add(fans);
		savedNum++;
	}

	public int getSavedNum() {
		return savedNum;
	}

	public void setSavedNum(int savedNum) {
		this.savedNum = savedNum;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

}
